# -*- coding: utf-8 -*-
import MySQLdb


def get_patch_connection():
    """
        manually create a connection for the patch database using MySQLdb.
    """
    conn = MySQLdb.connect(host='localhost',
                           user='dgw',
                           passwd='dgw',
                           db='userdemo',
                           port=3306,
                           charset="utf8")
    cursor = conn.cursor()
    return (conn, cursor)


def execute_sql(sql):
    conn, cursor = get_patch_connection()
    cursor.execute(sql)
    res = [line for line in cursor.fetchall()]
    print(cursor._executed)  # 打印执行的sql
    cursor.close()
    conn.close()
    return res
